home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 129_01 / 210rooma.c < prev    next >
Text File  |  1985-03-09  |  22KB  |  746 lines

  1. /************************************************************************/
  2. /*                rooma.c                 */
  3. /*        room code for Citadel bulletin board system        */
  4. /************************************************************************/
  5.  
  6. /************************************************************************/
  7. /*                history                 */
  8. /*                                    */
  9. /* 84Dec20 HAW&JLS The vp union eliminated from the system.        */
  10. /* 84Sep16 HAW    #if put in to handle CP/M-85 bug.            */
  11. /* 84Aug23 JLS & HAW  JLS's <F>orget Room Scheme implemented.        */
  12. /* 84Jul12 JLS & HAW  gotoRoom() and dumpRoom() modified for <S>kip.    */
  13. /* 84Jun23 HAW    Files now checked for CP/M R/O status.            */
  14. /* 84Jun23 HAW & JLS  Unused locals are zapped                */
  15. /* 84Apr04 HAW    Start 1.50a update                    */
  16. /* 83Feb24    Insert check for insufficient RAM, externs too low.    */
  17. /* 82Dec06 CrT    2.00 release.                        */
  18. /* 82Nov05 CrT    main() splits off to become citadel.c            */
  19. /************************************************************************/
  20.  
  21. #include <210ctdl.h>
  22.  
  23. /************************************************************************/
  24. /*                Contents                */
  25. /*                                    */
  26. /*    dumpRoom()        tells us # new messages etc        */
  27. /*    fileDir()        prints out a filename for a dir listing */
  28. /*    fillMailRoom()        set up Mail> from log record        */
  29. /*    gotoRoom()        handles "g(oto)" command for menu    */
  30. /*    init()            system startup initialization        */
  31. /*    initCitadel()                            */
  32. /*    initSysop()                            */
  33. /*    listRooms()        lists known rooms            */
  34. /*    openFile()        opens a .sys file            */
  35. /*    readSysTab()        restores system state from citadel.tab    */
  36. /*    roomExists()        returns slot# of named room else ERROR    */
  37. /*    setSpace()        set default disk and user#        */
  38. /*    setUp()                             */
  39. /*    systat()        shows current system status        */
  40. /*    wildCard()        expands ambiguous filenames        */
  41. /*    writeSysTab()        saves state of system in citadel.tab    */
  42. /*                                    */
  43. /************************************************************************/
  44.  
  45.  
  46. /************************************************************************/
  47. /*    dumpRoom() tells us # new messages etc                */
  48. /************************************************************************/
  49. dumpRoom()
  50. {
  51.     char hasSkipped, str[NAMESIZE];
  52.     int  fileDir();
  53.     int  i, count, loc, newCount, no;
  54.  
  55.     for (newCount=0, count=0, i=0;   i<MSGSPERRM;   i++) {
  56.  
  57.     loc    = roomBuf.msg[i].rbmsgLoc;
  58.     no    = roomBuf.msg[i].rbmsgNo ;
  59.     if (loc != ERROR) {
  60.         /* comparisons which take 64K wraparound into account:    */
  61.         if (no - oldestLo
  62.         < 0x8000
  63.         ) {
  64.         count++;
  65.         }
  66.  
  67.         /* don't boggle -- just checking against newestLo as of */
  68.         /* the last time we were  in this room:            */
  69.         if (no -
  70.            (logBuf.lbvisit[ logBuf.lbgen[thisRoom] & CALLMASK ]+1)
  71.         < 0x8000
  72.         ) {
  73.         newCount++;
  74.         }
  75.     }
  76.     }
  77.     /* lazy patch: */
  78.     if (newCount > count)   newCount = count;
  79.  
  80.     mPrintf(" %d messages\n ", count);
  81.     if (loggedIn && newCount > 0)   mPrintf(" %d new\n", newCount);
  82.     if ((roomBuf.rbflags & CPMDIR) && !expert) {
  83.     /* list directory also: */
  84.     doCR();
  85.     wildCard(fileDir, "*.*");
  86.     }
  87.  
  88.     for (i = LOBBY, hasSkipped = FALSE; i < MAXROOMS; i++)
  89.     if (roomTab[i].rtflags & INUSE &&
  90.            roomTab[i].rtgen == (logBuf.lbgen[i] >> GENSHIFT)) {
  91.         if (roomTab[i].rtflags & SKIP)
  92.         hasSkipped = TRUE;
  93.         else
  94.         if (roomTab[i].rtlastMessage - (
  95.             logBuf.lbvisit[logBuf.lbgen[i] & CALLMASK] + 1)
  96.                     < 0x8000)
  97.             break;
  98.     }
  99.  
  100.     if (i == MAXROOMS && hasSkipped) {
  101.     mPrintf("\n Skipped rooms: \n ");
  102.     for (i = LOBBY; i < MAXROOMS; i++)    /* No need to match gen #s. */
  103.         if (roomTab[i].rtflags & SKIP &&
  104.                roomTab[i].rtflags & INUSE) {
  105.         roomTab[i].rtflags &= ((BYTE - 1) - SKIP);   /* Clear. */
  106.         strcpy(str, roomTab[i].rtname);
  107.         if (roomTab[i].rtflags & CPMDIR)    strcat(str, ":");
  108.         else                    strcat(str, ">");
  109.         if (!(roomTab[i].rtflags & PUBLIC)) strcat(str, "*");
  110.         mPrintf(" %s ", str);
  111.         }
  112.     }
  113. }
  114.  
  115.  
  116. /************************************************************************/
  117. /*    fileDir() prints out one filename and size, for a dir listing    */
  118. /************************************************************************/
  119. fileDir(fileName)
  120. char *fileName;
  121. {
  122.     struct fcb    block;
  123.  
  124.     char tempName[NAMESIZE], tBuf[2*NAMESIZE];
  125.  
  126.     outFlag = OUTOK;
  127.  
  128.     unspace(fileName, tempName);
  129.     setFcb(&block,    tempName);
  130.     bdos(GETfILEsIZE, &block);        /* very slow on MMS BIOS! */
  131.  
  132.     FDSectCount    += block.fcbRecn;
  133.  
  134.     sprintf(tBuf, "%s%5d  ", fileName, block.fcbRecn);
  135.     putWord(tBuf);
  136.     mAbort();        /* chance to next(!)/pause/skip */
  137. }
  138.  
  139. /************************************************************************/
  140. /*    fillMailRoom()                            */
  141. /************************************************************************/
  142. fillMailRoom()
  143. {
  144.     int i;
  145.  
  146.     /* mail room -- copy messages in logBuf to room: */
  147.     for (i=0;  i<MSGSPERRM;  i++) {
  148.     roomBuf.msg[i].rbmsgLoc  = ERROR;
  149.     roomBuf.msg[i].rbmsgNo     = ERROR;
  150.     }
  151.     for (i=0;  i<MAILSLOTS;  i++) {
  152.     if (i==MSGSPERRM)   break;  /* for MSGSPRRM < MAILSLOTS */
  153.     roomBuf.msg[i].rbmsgLoc  = logBuf.lbslot[i];
  154.     roomBuf.msg[i].rbmsgNo     = logBuf.lbId[i]  ;
  155.     }
  156.     noteRoom();
  157. }
  158.  
  159. /************************************************************************/
  160. /*    gotoRoom() is the menu fn to travel to a new room        */
  161. /*    returns TRUE if room is Lobby>, else FALSE            */
  162. /************************************************************************/
  163. char gotoRoom(nam, mode)
  164. char *nam, mode;
  165. {
  166.     int  i, foundit, newStuff, nWest, roomNo;
  167.  
  168.     if (strLen(nam) == 0) {
  169.  
  170.     /* update log entry for current room:    */
  171.     if (mode != 'S') {
  172.         logBuf.lbgen[thisRoom] = roomBuf.rbgen << GENSHIFT;
  173.                  /* Clear SKIP bit */
  174.         roomTab[thisRoom].rtflags &= ((BYTE - 1) - SKIP);
  175.     }
  176.     foundit = FALSE;    /* leaves us in Lobby> if nothing found */
  177.     newStuff= FALSE;
  178.  
  179.     for (i    = 0
  180.          ;
  181.          i<MAXROOMS  &&  !foundit
  182.          ;
  183.          i++
  184.     ) {
  185.         if (
  186.         (roomTab[i].rtflags & INUSE)
  187.         &&
  188.         (roomTab[i].rtgen == (logBuf.lbgen[i] >> GENSHIFT) || aide)
  189.         &&
  190.         (roomTab[i].rtflags & SKIP) == 0
  191.         ) {
  192.         nWest = logBuf.lbvisit[logBuf.lbgen[i] & CALLMASK]+1;
  193.  
  194.         if (roomTab[i].rtlastMessage - nWest  < 0x8000) {
  195.             if (i != thisRoom    &&   (i != AIDEROOM   ||   aide))   {
  196.             foundit = i;
  197.             newStuff= TRUE;
  198.             }
  199.         }
  200.         }
  201.     }
  202.  
  203.     getRoom(foundit);
  204.     mPrintf("%s\n ", roomBuf.rbname);
  205.     } else {
  206.  
  207.     /* non-empty room name, so now we look for it: */
  208.     if (
  209.         (roomNo = roomExists(nam)) == ERROR
  210.         ||
  211.         (roomNo==AIDEROOM  &&  !aide)
  212.     ) {
  213.         mPrintf(" ?no %s room\n", nam);
  214.     } else {
  215.         /* update log entry for current room:   */
  216.         if (mode != 'S') {
  217.         if (loggedIn)
  218.             logBuf.lbgen[thisRoom] = roomBuf.rbgen << GENSHIFT;
  219.         roomTab[thisRoom].rtflags &= ((BYTE - 1) - SKIP);
  220.         }
  221.         getRoom(roomNo);
  222.  
  223.         /* if may have been unknown... if so, note it:    */
  224.         if ((logBuf.lbgen[thisRoom] >> GENSHIFT) != roomBuf.rbgen) {
  225.         logBuf.lbgen[thisRoom] = (
  226.             (roomBuf.rbgen << GENSHIFT) +
  227.             (MAXVISIT -1)
  228.         );
  229.         }
  230.     }
  231.     }
  232.     setUp(FALSE);
  233.     dumpRoom();
  234.     return  newStuff;    /* was thisRoom */
  235. }
  236.  
  237. /************************************************************************/
  238. /*    init() -- master system initialization                */
  239. /************************************************************************/
  240. init() {
  241.     char     getCh(), readSysTab(), toUpper();
  242.     char     *msgFile;
  243.     unsigned codend(), endExt(), externs(), topOfMem();
  244.     int      getText();     /* Forces load in BDS C 1.50a */
  245.  
  246.     whichIO = CONSOLE;
  247.     if (!readSysTab()) exit();
  248.     setSpace(homeDisk, homeUser);
  249.           /* 1K RAM might not actually be sufficient... */
  250.     if (topOfMem() - codEnd() < 1024)    {
  251.     printf("Not enough RAM!");
  252.     exit();
  253.     }
  254.     if (codEnd() > externs())    {
  255.     printf("Externs too low!");
  256.     exit();
  257.     }
  258.  
  259. #ifdef XYZZY
  260.     printf("code ends ....at  %u\n", codend()  );
  261.     printf("externs start at  %u\n", externs() );
  262.     printf("externs end   at  %u\n", endext()  );
  263.     printf("free RAM ends at  %u\n", topofmem());
  264. #e